<template>
  <div class="gl_contentBox gl_heightFull">
    <div class="demo-input-suffix gl_searchBox">
      <el-row :gutter="20">
        <el-col :span="4">
          <p>学生姓名</p>
          <el-input v-model="Api_GET_ClubCoachStudentInfosQO.StudentName" placeholder="请输入姓名" clearable size="mini" @change="getarchiiveList()" />
        </el-col>
        <el-col :span="4">
          <p>班级名称</p>
          <el-input v-model="Api_GET_ClubCoachStudentInfosQO.ClassName" placeholder="请输入班级名称" clearable size="mini" @change="getarchiiveList()" />
        </el-col>
        <el-col :span="4">
          <p>报告状态</p>
          <el-select v-model="ReportStatus" size="mini" @change="getarchiiveList()">
            <el-option label="全部" value=" " />
            <el-option label="已生成" :value="true" />
            <el-option label="未生成" :value="false" />
          </el-select>
        </el-col>
        <el-col :span="2.5">
          <el-button type="primary" style="margin-top:25px" size="mini" @click="getarchiiveList()">筛选</el-button>
        </el-col>
      </el-row>
    </div>
    <div style="margin-top:20px">
      <el-button type="warning" size="mini" @click="batch()">批量生成报告</el-button>
      <el-button type="primary" style="margin-left:10px;margin-bottom:15px" size="mini" :loading="morefalse" @click="morepush()">批量发送报告</el-button>
      <el-table ref="multipleTable" v-loading="tableLoading" class="gl_table_noBorder" size="mini" :data="tableData" @selection-change="select">
        <el-table-column type="selection" label-class-name="selection" width="50" />
        <el-table-column type="index" label="序号" align="center" width="50" />
        <el-table-column label="学员姓名" prop="name" />
        <el-table-column label="证件号码" prop="idCardNumber" />
        <el-table-column label="联系方式">
          <template slot-scope="{row}">
            <template v-if="row.studentContacts && row.studentContacts.length">
              <div v-for="(item, index) in row.studentContacts" :key="index">{{ item.contactType.name }} {{ item.phoneNumber }}</div>
            </template>
          </template>
        </el-table-column>
        <el-table-column label="班级名称">
          <template slot-scope="{ row }">
            <span v-for="(item, index) in row.classes" :key="index">
              {{ item.name }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="最新生成时间">
          <template slot-scope="{ row }">
            <span v-if="row.latestGenerationTime">
              {{ row.latestGenerationTime | FormatDate('yyyy-MM-dd HH:mm:ss') }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="上次推送时间">
          <template slot-scope="{ row }">
            <span v-if="row.lastPushTime">
              {{ row.lastPushTime | FormatDate('yyyy-MM-dd HH:mm:ss') }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template slot-scope="{ row }">
            <el-button type="text" size="mini" style="color:#1990FF" @click="member(row)">学员资料</el-button>
            <el-button type="text" size="mini" style="color:#1990FF" @click="create(row)">生成报告</el-button>
            <el-button type="text" size="mini" style="color:#1990FF" @click="push(row.id)">推送报告</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 生成学员报告 -->
    <el-dialog
      title="生成学员报告"
      class="gl_dialog_TitleLine gl_dl_footer card"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      width="1000px"
      top="25vh"
    >
      <el-scrollbar>
        <p style="margin-right:15px">选择生成周期</p>
        <el-date-picker v-model="freeDay" type="daterange" range-separator="至" start-placeholder="请选择日期" end-placeholder="请选择日期" size="mini" value-format="yyyy-MM-dd" style="width:50%" />
      </el-scrollbar>
      <p style="margin-top:15px">请选择模板</p>
      <el-select v-model="templateId" size="mini">
        <el-option v-for="(item,index) in template" :key="index" :value="item.id" :label="item.name" />
      </el-select>
      <p style="margin-top:15px">请选择评语</p>
      <el-select v-model="wordid" size="mini">
        <el-option v-for="(item,index) in wordPool" :key="index" style="width:500px" :value="item.id" :label="item.name" />
      </el-select>
      <p style="display:flex;justify-content:space-around;margin-top:15px;margin-bottom:15px">
        <el-button size="mini" type="primary" @click="dialogVisible = false">取消</el-button>
        <el-button size="mini" type="primary" :loading="addloading" @click="addArchives()">生成</el-button>
      </p>
      <p>报告记录</p>
      <el-table v-loading="tableLoading1" class="gl_table_noBorder" size="mini" :data="studentArchives">
        <el-table-column label="生成周期" width="180">
          <template slot-scope="{ row }">
            <span>
              {{ row.beginDate | FormatDate('yyyy-MM-dd') }} --
            </span>
            <span>
              {{ row.endDate | FormatDate('yyyy-MM-dd') }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="点评">
          <template slot-scope="{row}">

            <span>
              {{ row.comment || '--' }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="180">
          <template slot-scope="{ row }">
            <el-button type="text" size="mini" style="color:#1990FF" @click="previewTemp(row)">预览</el-button>
            <el-button type="text" size="mini" style="color:#1990FF" @click="editRemark(row)">编辑点评</el-button>
            <el-button type="text" size="mini" style="color:#1990FF" @click="close(row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-row class="gl_pt_15" style="text-align: right;">
        <el-pagination
          :current-page="Api_GET_ClubStudentReportQO.Page"
          :page-size="Api_GET_ClubStudentReportQO.MaxResultCount"
          :total="totalPageTem"
          layout="total,sizes,prev,pager,next,jumper"
          :page-sizes="[10, 20, 30, 40]"
          @size-change="sizeChangetem"
          @current-change="pageIndexChangetem"
        />
      </el-row>

    </el-dialog>
    <!-- 编辑评语 -->
    <el-dialog
      title="编辑评语"
      class="gl_dialog_TitleLine gl_dl_footer card"
      :visible.sync="dialogEditVisible"
      :close-on-click-modal="false"
      width="1000px"
      top="25vh"
    >
      <el-scrollbar>
        <el-radio-group v-model="radio" style="width:100%;margin-bottom:16px">
          <el-radio label="edit" style="margin-bottom:16px">编辑评语</el-radio>
          <el-input v-model="radioworld" type="textarea" :rows="8" style="margin-bottom:16px" :disabled="radio==='edit'?false:true" />
          <el-radio label="add" style="margin-bottom:16px">选择评语</el-radio>
        </el-radio-group>
      </el-scrollbar>
      <el-table ref="tablew" v-loading="tableLoading2" class="gl_table_noBorder" size="mini" :data="wordPool" @selection-change="selection">
        <el-table-column type="selection" label-class-name="selection" width="50" :selectable="selectable" />
        <el-table-column type="index" label="序号" width="55" />
        <el-table-column prop="name" label="词条名称" align="center" />
        <el-table-column prop="name" label="词条类型" align="center">
          <template slot-scope="{row}">
            <div>{{ row.wordPoolType ? row.wordPoolType.name : '' }}</div>
          </template>
        </el-table-column>
        <el-table-column label="词条内容" prop="description" />
        <el-table-column label="创建人" prop="creatorName" />
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="dialogEditVisible = false">取消</el-button>
        <el-button size="mini" type="primary" :loading="woldfalse" @click="addOrEdi()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 批量生成报告 -->
    <el-dialog
      title="批量生成报告"
      class="gl_dialog_TitleLine gl_dl_footer card"
      :visible.sync="dialogBachVisible"
      :close-on-click-modal="false"
      width="1000px"
      top="25vh"
    >
      <p>选择生成周期</p>
      <el-date-picker v-model="morefreeDay" type="daterange" range-separator="至" start-placeholder="请选择日期" end-placeholder="请选择日期" size="mini" value-format="yyyy-MM-dd" style="width:50%" />
      <p style="margin-top:15px">请选择模板</p>
      <el-select v-model="templateId" size="mini" style="margin-top:5px;margin-bottom:15px">
        <el-option v-for="(item,index) in template" :key="index" :value="item.id" :label="item.name" />
      </el-select>
      <el-table ref="table" class="gl_table_noBorder" size="mini" :data="wordPoolmore" @selection-change="moreselection">
        <el-table-column type="selection" label-class-name="selection" width="50" />
        <el-table-column type="index" label="序号" align="center" width="55" />
        <el-table-column label="词条名称" width="110" align="center" prop="name" />
        <el-table-column label="词条类型" width="110" align="center" prop="wordPoolType.name" />
        <el-table-column label="适用性别" width="95" align="center">
          <template slot-scope="{row}">
            {{ row.genderCode === 'M' ? '男': row.genderCode === 'W' ? '女':'通用' }}
          </template>
        </el-table-column>
        <el-table-column label="词条内容" prop="description" />
        <el-table-column label="创建人" width="100" prop="creatorName" />
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="closemore">取 消</el-button>
        <el-button size="mini" type="primary" :loading="goflase" @click="goReport">下一步</el-button>
      </span>
    </el-dialog>
    <!-- 批量生成报告结果 -->
    <el-dialog
      title="批量生成报告结果"
      class="gl_dialog_TitleLine gl_dl_footer card"
      :visible.sync="dialogGoBachVisible"
      :close-on-click-modal="false"
      width="1400px"
      top="25vh"
    >
      <el-scrollbar>
        <p style="margin-top:14px;margin-bottom:16px">日期:</p>
      </el-scrollbar>
      <el-table class="gl_table_noBorder" size="mini" :data="tableBach" @selection-change="select1">
        <el-table-column type="selection" label-class-name="selection" width="50" />
        <el-table-column type="index" label="序号" width="55" />
        <el-table-column label="姓名" prop="name" />
        <el-table-column label="性别" prop="gender.name" />
        <!-- <el-table-column label="联系方式" /> -->
        <el-table-column label="班级名称">
          <template slot-scope="{ row }">
            <span v-for="(item,index) in row.classes" :key="index" style="margin-right:10px">
              {{ item.name }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="报告生成状态">
          <template slot-scope="{ row }">
            <span>
              {{ row.status === true ? '已生成' : '未生成' }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="评语" prop="comment" />
        <el-table-column label="操作" width="180px">
          <template slot-scope="{ row, $index }">
            <el-button type="text" size="mini" style="color:#1990FF" @click="alterRemark(row, $index)">修改评语</el-button>
            <el-button type="text" size="mini" style="color:#1990FF" @click="close(row, $index)">删除</el-button>
            <el-button type="text" size="mini" style="color:#1990FF" @click="push(row.studentId)">发送报告</el-button>
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="dialogGoBachVisible = false">取消</el-button>
        <el-button size="mini" type="primary" :loading="morefalse" @click="morepush1()">发送报告</el-button>
      </span>
    </el-dialog>
    <!-- 修改评语 -->
    <el-dialog
      title="教练点评"
      class="gl_dialog_TitleLine gl_dl_footer card"
      :visible.sync="dialogAlterVisible"
      :close-on-click-modal="false"
      width="1000px"
      top="25vh"
    >
      <el-scrollbar>
        <el-input v-model="world" type="textarea" :rows="8" />
      </el-scrollbar>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="dialogAlterVisible = false">取 消</el-button>
        <el-button size="mini" type="primary" :loading="visfalse" @click="editw">确认</el-button>
      </span>
    </el-dialog>
    <el-row class="gl_pt_15" style="text-align: right;">
      <el-pagination
        :current-page="Api_GET_ClubCoachStudentInfosQO.Page"
        :page-size="Api_GET_ClubCoachStudentInfosQO.MaxResultCount"
        :total="totalPage"
        layout="total,sizes,prev,pager,next,jumper"
        :page-sizes="[10, 20, 30, 40]"
        @size-change="sizeChange"
        @current-change="pageIndexChange"
      />
    </el-row>
    <!-- 新建模板弹窗 -->
    <Template ref="template" />

    <!-- 纯为本报告 -->
    <el-dialog
      title="文本报告"
      class="gl_dialog_TitleLine gl_dl_footer card"
      :visible.sync="dialogTextVisible"
      :close-on-click-modal="false"
      width="650px"
      top="25vh"
    >
      <el-scrollbar>
        <div class="header">报告样式</div>
        <div class="header_foot">{{ textworld }}</div>
        <div class="header">教练评语</div>
        <div class="header_foot">{{ teachworld }}</div>
      </el-scrollbar>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="dialogTextVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import Template from './template.vue';
import { api_POST_ClubStudentReportPushStudentReportList, api_GET_ClubMessageId, api_POST_ClubStudentReportPushStudentReportRegisterStudentId, api_GET_ClubCoachStudentInfos, api_GET_ClubWordPool, api_POST_ClubStudentReport, api_GET_ClubMessageTemplate, api_GET_ClubStudentReport, api_DELETE_ClubStudentReportId, api_POST_ClubStudentReportStudentReportList, api_PUT_ClubStudentReportId } from '@/extend/api/hallswaggerApi/app.js';
import { Api_GET_ClubMessageIdQO, UpdateStudentReportInput, CreateStudentReportListInput, Api_GET_ClubCoachStudentInfosQO, Api_GET_ClubWordPoolQO, CreateStudentReportInput, Api_GET_ClubWordPoolIdQO, Api_GET_ClubMessageTemplateQO, Api_GET_ClubStudentReportQO } from '@/lib/form/hall/swaggerForm';
export default {
  components: {
    Template
  },
  data() {
    return {
      studentname: '', // 学员姓名
      textworld: '', // 纯文本报告
      teachworld: '', // 教练评语
      dialogTextVisible: false,
      previewUrl: '',
      woldfalse: false,
      tableLoading2: false,
      morestudentsld: [],
      morefalse: false,
      visfalse: false,
      goflase: false,
      tableLoading1: false,
      addloading: false,
      currentPage: 1,
      woindex: '',
      id: '', // 评语id
      world: '',
      studentsld: [],
      worldid: '', // 编辑评语id
      selectworld: [],
      radioworld: '',
      Api_GET_ClubStudentReportQO: new Api_GET_ClubStudentReportQO(), // 学员报告列表
      studentArchives: [],
      CreateStudentReportListInput: new CreateStudentReportListInput(), // 批量报告
      morefreeDay: [],
      templateId: '',
      template: [],
      Api_GET_ClubMessageTemplateQO: new Api_GET_ClubMessageTemplateQO(),
      wordid: '',
      wordPool: [],
      wordPoolmore: [], // 批量生成报告的评语
      Api_GET_ClubWordPoolIdQO: new Api_GET_ClubWordPoolIdQO(), // 获取词库
      tableLoading: false,
      freeDay: [],
      studentId: '',
      registerId: '',
      CreateStudentReportInput: new CreateStudentReportInput(),
      Api_GET_ClubWordPoolQO: new Api_GET_ClubWordPoolQO(),
      totalPage: 0,
      totalPageTem: 0,
      Api_GET_ClubCoachStudentInfosQO: new Api_GET_ClubCoachStudentInfosQO(), // 学生档案
      UpdateStudentReportInput: new UpdateStudentReportInput(), // 修改报告
      tableReport: [],
      dialogVisible: false, // 生成学生报告
      dialogEditVisible: false, // 编辑评语
      dialogBachVisible: false, // 修改评语
      dialogGoBachVisible: false, // 批量生成报告结果
      dialogAlterVisible: false, // 修改评语
      paymentTime: [],
      tableData: [],
      tableBach: [],
      radio: 'edit',
      CommentStatus: '',
      ReportStatus: '',
      sex: [] // 性别
    };
  },
  computed: {
    currentInfo () {
      return this.$store.state.user.info;
    }
  },
  watch: {
    freeDay: {
      immediate: true,
      deep: true,
      handler(val) {
        if (val && val.length !== 0) {
          this.changeProportion(val);
        }
      }
    },
    morefreeDay: {
      immediate: true,
      deep: true,
      handler(val) {
        if (val && val.length !== 0) {
          this.morechangeProportion(val);
        }
      }
    }
  },
  created() {
    this.getarchiiveList();
  },
  methods: {
    editw() {
      this.visfalse = true;
      this.UpdateStudentReportInput.comment = this.world;
      console.log(this.UpdateStudentReportInput);
      api_PUT_ClubStudentReportId(this.id, this.UpdateStudentReportInput).then(res => {
        this.$message({
          message: '修改成功',
          type: 'success'
        });
        this.visfalse = false;
        this.dialogAlterVisible = false;
        this.tableBach[this.woindex].comment = this.world;
      }, error => {
        this.visfalse = false;
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    // 删除报告记录
    close(row, index) {
      this.$confirm(`您确定要删除吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          api_DELETE_ClubStudentReportId(row.id).then(res => {
            this.$message({
              message: '删除成功',
              type: 'success'
            });
            this.getStudentReport();
            this.woindex = index;
            this.tableBach.splice(index, 1);
          }, error => {
            const _msg = error.error.message || error.message;
            this.$message({ type: 'error', message: _msg });
          });
        });
    },
    addOrEdi() {
      this.woldfalse = true;
      if (this.radio === 'edit') {
        console.log(this.radioworld);
        this.UpdateStudentReportInput.isFromWordPool = false;
        this.UpdateStudentReportInput.comment = this.radioworld;
      } else {
        this.UpdateStudentReportInput.comment = '';
        this.UpdateStudentReportInput.isFromWordPool = true; //  是否使用词库 type: boolean
        this.UpdateStudentReportInput.wordPoolId = this.selectworld[0]; //  词库Id type: string
      }
      console.log(this.UpdateStudentReportCommentInput);
      // if (this.radioworld === '' && this.selectworld[0] === '') {
      //   this.$message('请选择评语');
      //   return;
      // }
      api_PUT_ClubStudentReportId(this.worldid, this.UpdateStudentReportInput).then(res => {
        this.$refs.tablew.clearSelection();
        this.$message({
          message: '修改成功',
          type: 'success'
        });
        this.woldfalse = false;
        this.getStudentReport();
        this.dialogEditVisible = false;
      }, error => {
        this.woldfalse = false;
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    select(val) {
      this.studentsld = [];
      this.sex = [];
      console.log(val);
      if (val.length > 0) {
        val.forEach(item => {
          this.studentsld.push(item.id);
          this.sex.push(item.gender);
        });
      }
      console.log(this.sex);
    },
    select1(val) {
      this.morestudentsld = [];
      if (val.length > 0) {
        val.forEach(item => {
          this.morestudentsld.push(item.studentId);
        });
      }
    },
    moreselection(val) {
      this.selectworld = [];
      if (val.length > 0) {
        val.forEach(item => {
          this.selectworld.push(item.id);
        });
      }
    },
    selection(val) {
      this.selectworld = [];
      if (val.length === 1) {
        val.forEach(item => {
          this.selectworld.push(item.id);
        });
      } else {
        val.forEach(item => {
          this.$message({
            message: '请选择数据',
            type: 'warning'
          });
          this.$refs.tablew.clearSelection();
          this.$refs.tablew.toggleRowSelection(val[1]);
        });
      }
    },
    // 报告记录
    getStudentReport(page) {
      this.Api_GET_ClubStudentReportQO.Page = page || 1;
      this.Api_GET_ClubStudentReportQO.SkipCount = (this.Api_GET_ClubStudentReportQO.Page - 1) * this.Api_GET_ClubStudentReportQO.MaxResultCount;
      this.Api_GET_ClubStudentReportQO.Sorting = 'creationTime DESC';
      this.Api_GET_ClubStudentReportQO.RegisterStudentId = this.studentId;
      this.tableLoading1 = true;
      // GenderCodes
      api_GET_ClubStudentReport(this.Api_GET_ClubStudentReportQO).then(res => {
        this.studentArchives = res.items;
        this.tableLoading1 = false;
        this.totalPageTem = res.totalCount;
      }, error => {
        this.tableLoading1 = false;
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    getarchiiveList(page) {
      this.$nextTick(() => {
        this.$refs.multipleTable.clearSelection();
      });
      this.tableLoading = true;
      this.Api_GET_ClubCoachStudentInfosQO.Sorting = 'creationTime DESC';
      this.Api_GET_ClubCoachStudentInfosQO.Page = page || 1;
      this.Api_GET_ClubCoachStudentInfosQO.SkipCount = (this.Api_GET_ClubCoachStudentInfosQO.Page - 1) * this.Api_GET_ClubCoachStudentInfosQO.MaxResultCount;
      this.Api_GET_ClubCoachStudentInfosQO.CoachId = this.$route.query.id;
      this.Api_GET_ClubCoachStudentInfosQO.ReportStatus = this.ReportStatus;
      this.Api_GET_ClubCoachStudentInfosQO.CommentStatus = this.CommentStatus;
      console.log(this.Api_GET_ClubCoachStudentInfosQO);
      api_GET_ClubCoachStudentInfos(this.Api_GET_ClubCoachStudentInfosQO).then(res => {
        this.tableLoading = false;
        this.tableData = res.items;
        this.totalPage = res.totalCount;
        console.log(res);
      }, error => {
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    check() {
      this.$router.push({ name: 'CoachType' });
    },
    changeProportion(val) {
      console.log(val);
      this.CreateStudentReportInput.beginDate = val[0];
      this.CreateStudentReportInput.endDate = val[1];
    },
    morechangeProportion(val) {
      this.CreateStudentReportListInput.beginDate = val[0];
      this.CreateStudentReportListInput.endDate = val[1];
    },
    // 打开生成报告页面
    create(row) {
      this.studentname = row.name;
      this.freeDay = [];
      this.templateId = '';
      this.wordid = '';
      this.studentId = '';
      this.registerId = '';
      this.CreateStudentReportInput = new CreateStudentReportInput();
      // 评语
      console.log(row);
      if (row.gender === '男') {
        this.Api_GET_ClubWordPoolIdQO.GenderCodes = ['M', 'X'];
      } else {
        this.Api_GET_ClubWordPoolIdQO.GenderCodes = ['W', 'X'];
      }
      this.Api_GET_ClubWordPoolIdQO.IncludeWordPoolType = true; // type: boolean
      this.Api_GET_ClubWordPoolIdQO.IncludeWordGender = true; // type: boolean
      this.Api_GET_ClubWordPoolIdQO.MaxResultCount = 999;
      api_GET_ClubWordPool(this.Api_GET_ClubWordPoolIdQO).then(res => {
        for (var i = 0; i < res.items.length; i++) {
          if (res.items[i].wordPoolTypeCode !== 'ReportComment') {
            res.items.splice(i, 1);
            i--;
          }
        }
        this.wordPool = res.items;
      });
      // 模板
      this.Api_GET_ClubMessageTemplateQO.IsEnabled = true; // type: boolean
      this.Api_GET_ClubMessageTemplateQO.IncludeMessageTemplateType = true; // type: boolean
      this.Api_GET_ClubMessageTemplateQO.IncludeMessageTemplateStyle = true; // type: boolean
      api_GET_ClubMessageTemplate(this.Api_GET_ClubMessageTemplateQO).then(res => {
        for (var i = 0; i < res.items.length; i++) {
          if (res.items[i].messageTemplateTypeCode !== 'StudentReport') {
            res.items.splice(i, 1);
            i--;
          }
        }
        this.template = res.items;
      });
      console.log(row);
      this.studentId = row.id;
      this.registerId = row.registerId;
      this.dialogVisible = true;
      this.getStudentReport();
    },
    editRemark(row) {
      console.log(row);
      this.UpdateStudentReportInput.beginDate = row.beginDate;
      this.UpdateStudentReportInput.endDate = row.endDate;
      this.worldid = row.id;
      this.radioworld = '';
      this.selectworld = [];
      this.radio = 'edit';
      this.dialogEditVisible = true;
    },
    selectable() {
      return this.radio === 'add';
    },
    batch() {
      this.CreateStudentReportListInput = new CreateStudentReportListInput();
      this.morefreeDay = [];
      this.templateId = '';
      if (this.studentsld.length === 0) {
        this.$message(
          {
            message: '请选择学员',
            type: 'warning'
          });
        return;
      }
      // 评语
      var selectsex = 0;
      for (var i = 0; i < this.sex.length; i++) {
        if (this.sex[i] === '男') {
          selectsex + 0;
        } else {
          selectsex = selectsex + 1;
        }
      }
      console.log(selectsex);
      if (selectsex === 0) {
        this.Api_GET_ClubWordPoolIdQO.GenderCodes = ['M', 'X'];
      } else if (selectsex === this.sex.length) {
        this.Api_GET_ClubWordPoolIdQO.GenderCodes = ['W', 'X'];
      } else {
        this.Api_GET_ClubWordPoolIdQO.GenderCodes = ['M', 'W', 'X'];
      }
      this.Api_GET_ClubWordPoolIdQO.IncludeWordPoolType = true; // type: boolean
      this.Api_GET_ClubWordPoolIdQO.IncludeWordGender = true; // type: boolean
      api_GET_ClubWordPool(this.Api_GET_ClubWordPoolIdQO).then(res => {
        for (var i = 0; i < res.items.length; i++) {
          if (res.items[i].wordPoolTypeCode !== 'ReportComment') {
            res.items.splice(i, 1);
            i--;
          }
        }
        this.wordPoolmore = res.items;
      });
      // 模板
      this.Api_GET_ClubMessageTemplateQO.IsEnabled = true; // type: boolean
      this.Api_GET_ClubMessageTemplateQO.IncludeMessageTemplateType = true; // type: boolean
      this.Api_GET_ClubMessageTemplateQO.IncludeMessageTemplateStyle = true; // type: boolean
      api_GET_ClubMessageTemplate(this.Api_GET_ClubMessageTemplateQO).then(res => {
        for (var i = 0; i < res.items.length; i++) {
          if (res.items[i].messageTemplateTypeCode !== 'StudentReport') {
            res.items.splice(i, 1);
            i--;
          }
        }
        this.template = res.items;
      });
      this.Api_GET_ClubWordPoolQO.IsEnabled = true; // type: boolean
      this.Api_GET_ClubWordPoolQO.IncludeWordPoolType = true; // type: boolean
      this.Api_GET_ClubWordPoolQO.IncludeWordGender = true; // type: boolean
      api_GET_ClubWordPool(this.Api_GET_ClubWordPoolQO).then(res => {
        console.log(res);
      }, error => {
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
      this.dialogBachVisible = true;
      // this.$refs.multipleTable.clearSelection();
    },
    goReport() {
      this.goflase = true;
      if (this.morefreeDay.length === 0) {
        this.$message({
          message: '请选择生成周期',
          type: 'warning'
        });
        this.goflase = false;
        return;
      }
      if (this.templateId === '') {
        this.$message({
          message: '请选择模板',
          type: 'warning'
        });
        this.goflase = false;
        return;
      }
      if (this.selectworld.length === 0) {
        this.$message({
          message: '请选择评语',
          type: 'warning'
        });
        this.goflase = false;
        return;
      }
      this.dialogBachVisible = false;
      this.CreateStudentReportListInput.studentIds = this.studentsld; //  学员Ids type: string
      this.CreateStudentReportListInput.wordPoolIds = this.selectworld; //  词库Ids type: string
      this.CreateStudentReportListInput.messageTemplateId = this.templateId; //  报告模板Id type: string
      this.UpdateStudentReportInput.beginDate = this.CreateStudentReportListInput.beginDate;
      this.UpdateStudentReportInput.endDate = this.CreateStudentReportListInput.endDate;
      api_POST_ClubStudentReportStudentReportList(this.CreateStudentReportListInput).then(res => {
        console.log(res);
        this.CreateStudentReportListInput = new CreateStudentReportListInput();
        this.goflase = false;
        this.tableBach = res;
        this.studentsld = [];
        this.dialogGoBachVisible = true;
        this.UpdateStudentReportInput.isFromWordPool = false;
        this.$refs.multipleTable.clearSelection();
      }, error => {
        this.goflase = false;
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    // 修改评语
    alterRemark(row, index) {
      this.woindex = index;
      console.log(row);
      this.id = row.id;
      this.world = '';
      this.dialogAlterVisible = true;
    },
    // 生成报告
    addArchives() {
      this.addloading = true;
      this.CreateStudentReportInput.messageTemplateId = this.templateId;
      this.CreateStudentReportInput.wordPoolId = this.wordid;
      this.CreateStudentReportInput.registerStudentId = this.studentId; //  学员Id type: string
      console.log(this.CreateStudentReportInput);
      if (this.freeDay.length === 0) {
        this.$message({
          message: '请选择生成周期',
          type: 'warning'
        });
        this.addloading = false;
        return;
      }
      if (this.templateId === '') {
        this.$message({
          message: '请选择模板',
          type: 'warning'
        });
        this.addloading = false;
        return;
      }
      if (this.wordid === '') {
        this.$message({
          message: '请选择评语',
          type: 'warning'
        });
        this.addloading = false;
        return;
      }
      api_POST_ClubStudentReport(this.CreateStudentReportInput).then(res => {
        this.$message({
          message: '创建成功',
          type: 'success'
        });
        this.dialogVisible = false;
        this.addloading = false;
        console.log(res);
        this.CreateStudentReportInput = new CreateStudentReportInput();
        this.studentArchives[0] = res;
        this.getStudentReport();
        this.templateId = '';
        this.wordid = '';
        this.studentId = '';
      }, error => {
        this.addloading = false;
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    // 推送报告
    push(row) {
      this.tableLoading = true;
      api_POST_ClubStudentReportPushStudentReportRegisterStudentId(row).then(res => {
        this.tableLoading = false;
        this.$message({
          message: '推送成功',
          type: 'success'
        });
      }, error => {
        this.tableLoading = false;
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    member(row) {
      this.$router.push({ 'name': 'StudentType', query: { 'rid': row.registerId, 'id': row.id, 'ed': 'U' }});
    },
    morepush() {
      this.morefalse = true;
      if (this.studentsld.length === 0) {
        this.morefalse = false;
        this.$message({
          message: '请选择学员',
          type: 'warning'
        });
        return;
      }
      api_POST_ClubStudentReportPushStudentReportList(this.studentsld).then(res => {
        this.$message({
          message: '推送成功',
          type: 'success'
        });
        this.morefalse = false;
        this.studentsld = [];
        this.getarchiiveList();
      }, error => {
        this.morefalse = false;
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
        this.getarchiiveList();
      });
    },
    morepush1() {
      this.morefalse = true;
      console.log(this.morestudentsld.length);
      if (this.morestudentsld.length === 0) {
        this.morefalse = false;
        this.$message({
          message: '请选择学员',
          type: 'warning'
        });
        return;
      }
      api_POST_ClubStudentReportPushStudentReportList(this.morestudentsld).then(res => {
        this.$message({
          message: '推送成功',
          type: 'success'
        });
        this.dialogGoBachVisible = false;
        this.morefalse = false;
        this.morestudentsld = [];
      }, error => {
        this.morefalse = false;
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    closemore() {
      this.$refs.multipleTable.clearSelection();
      this.dialogBachVisible = false;
      this.morefreeDay = [];
      this.templateId = '';
    },
    // 预览
    previewTemp(row) {
      console.log(row);

      const _json = new Api_GET_ClubMessageIdQO();
      _json.IncludeMessageTemplate = true;
      _json.IncludeMessageTemplateType = true;
      _json.IncludeMessageTemplateStyle = true;
      console.log(this.currentInfo);
      api_GET_ClubMessageId(row.messageId, _json).then(res => {
        if (res.messageTemplate.messageTemplateTextStyle !== null && res.messageTemplate.messageTemplateH5Style === null) {
          this.$refs.template.dialogEditVisible = false;
          this.dialogTextVisible = true;
          this.textworld = `学员报告生成通知。${this.studentname}家长您好，${this.studentname}在${this.currentInfo.organizationUnitEdition.organizationUnit.displayName}道馆${row.beginDate.split('T')[0]}至${row.endDate.split('T')[0]}的表现情况已生成，请您查收。`;
          this.teachworld = row.comment;
        } else {
          this.$refs.template.dialogEditVisible = true;
          this.dialogTextVisible = false;
        }
        this.$refs.template.msgId = res.id;
        this.$refs.template.studentId = this.studentId;
        this.$refs.template.registerId = this.registerId;
      });
    },
    sizeChange(MaxResultCount) {
      this.Api_GET_ClubCoachStudentInfosQO.MaxResultCount = MaxResultCount;
      this.getarchiiveList();
    },
    pageIndexChange(currentPage) {
      this.getarchiiveList(currentPage);
    },
    sizeChangetem(MaxResultCount) {
      this.Api_GET_ClubStudentReportQO.MaxResultCount = MaxResultCount;
      this.getStudentReport();
    },
    pageIndexChangetem(currentPage) {
      this.getStudentReport(currentPage);
    }
  }

};
</script>

<style lang="scss" scoped>
.header {
  font-size: 16px;
  font-weight: 900;
  color: #717178;
}
.header_foot{
   font-size: 12px;
  font-weight: 900;
  color: rgb(139, 137, 137);
  margin-top: 5px;
  margin-bottom: 15px;

}
</style>
